<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE>
<html>
	<head>
	<meta charset="UTF-8">
		<title>登录</title>
	<script src="jquery-1.11.3/jquery.min.js"></script>
<script  type="text/javascript">
//在全局定义验证码    
var code;   
//产生验证码     
window.onload = function() {  
  createCode();  
}  


function createCode() {  
  code = "";  
//验证码的长度
  var codeLength =6;    
  var checkCode = document.getElementById("checkCode");  
//随机数
  var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',  
      'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
//循环操作     
  for(var i = 0; i < codeLength; i++) { 
	//取得随机数的索引 
      var charIndex = Math.floor(Math.random() * 36);      
    //根据索引取得随机数加到code上
      code += random[charIndex];      
  }  
//把code值赋给验证码
  checkCode.value = code;      
}  
//校验验证码     
function validate() {
	
	//所有验证是否全部通过标识
	//取得输入的验证码并转化为大写  
  var inputCode = document.getElementById("input1").value.toUpperCase();  
 	console.info("inputCode:" +inputCode)
 	console.info("Code:" +code)
//若输入的验证码长度为0
  if(inputCode.length <= 0) {
	//则弹出请输入验证码   
      alert("请输入验证码！"); 
      return false;
    //若输入的验证码与产生的验证码不一致时
 
  } else if(inputCode != code) {      
	//则弹出验证码输入错误 
      alert("验证码输入错误！请重新输入验证码"); 
    //如果输入验证码错误 刷新验证码
      createCode(); 
      return false;

  } else { 
	//输入验证码正确 返回true 登陆成功
	
      return true;
  }  
}  
</script>
<style type="text/css">
    .code
    {
      font-family: Arial;
      font-style: italic;
      color: AliceBlue;
      border: 0;
      padding: 2px 3px;
      letter-spacing: 3px;
      font-weight: bolder;
    }
    .unchanged
    {
      border: 0;
    }
  </style>

	</head>
	<body background="${basePath}loginResource/img/lvkui.jpg">
		<form class="form-horizontal" action="UserLoginServlet" method="post"> 
        <div class="form-group" align="center">
    <label for="inputEmail3" class="col-sm-2 control-label"><font color="red">账号</font></label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="textNum" name="textNum" placeholder="Number">
    </div>
  </div>
  <div class="form-group" align="center">
    <label for="inputPassword3" class="col-sm-2 control-label"><font color="red">密码</font></label>
    <div class="col-sm-10">
      <input type="password" class="form-control" id="textPsw" name="textPsw" placeholder="Password">
    </div>
  </div>
 
  <div align="center">
	<label class="control-label" for="inputEmail"><font color="red">验证码</font></label>
	<br/>
	<input type="text" id="input1" />       
	 <br/>
	<input type="text" readonly="readonly" id="checkCode" class="unchanged" style="width: 80px;background: #66FF99"/>
	<a href="#" onclick="createCode()"><font color="blue">看不清</font></a>
	</div>
  <div class="form-group" align="center">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" class="btn btn-default" onclick="return validate();" ><font color="red" face="楷书">登录</font></button>
    </div>
  </div>
</form>
</body>
</html>
